package com.ssm.controller;

import com.ssm.po.Admin;
import com.ssm.service.adminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class AdminController {
    @Autowired
    private adminService adminService;

    @RequestMapping("index")
    public String index(){
        return "index";
    }

    @RequestMapping("doLogin")
    public String doLogin(Admin admin, Model model, HttpServletRequest request){
        if (!adminService.doLogin(admin)){
            model.addAttribute("msg","用户名或密码错误，请重试");
            return "index";
        }else {
            request.getSession(true).setAttribute("admin",admin);
            return "redirect:/class/showSearch";
        }
    }

    @RequestMapping("doQuit")
    public String doQuit(HttpServletRequest request){
        request.getSession(true).removeAttribute("admin");
        return "index";
    }

}
